﻿Public Class ViewSharedSettings

    Private Sub Button_Click_1(sender As Object, e As Windows.RoutedEventArgs)
        If Not My.Settings.AllowUserChangeGlobalSharedFolder Then
            MsgBox("Vous n'etes pas autorisé à changer ce paramètre", MsgBoxStyle.Critical)
            Return
        End If
        If MsgBox("Cette action necessitera un redemarrage de l'outil", MsgBoxStyle.OkCancel) = MsgBoxResult.Ok Then
            Dim txt = New Windows.Controls.TextBox()
            Dim fbd = New System.Windows.Forms.FolderBrowserDialog()
            If fbd.ShowDialog() = Windows.Forms.DialogResult.OK Then
                If IO.File.Exists(IO.Path.Combine(fbd.SelectedPath, "globalconfig.xml")) Then
                    CType(DataContext, ViewModelSharedSettings).GlobalFolder = fbd.SelectedPath
                    MsgBox("Changement effectue avec succes . Veuillez redemarrer l'outil")

                    ClearNodeTab(ModuleDashboarding._rootnode)
                    ModuleDashboarding._uiservice.V2ViewModelAccordeonMenu.Indicateurs.Body.Remove(ModuleDashboarding._rootnode)
                Else
                    MsgBox("Impossible de trouver  le fichier de configuration ! ", vbCritical)
                End If
            End If
        End If
    End Sub

    Sub ClearNodeTab(node As OMANE.Common.UI.V2ViewModelTabGroup)

        If node IsNot Nothing Then

            node.TabSection = Nothing

            If node.TabGroup IsNot Nothing Then

                node.TabGroup.Clear()

            End If

        End If

        For Each c In node.Children

            ClearNodeTab(TryCast(c, OMANE.Common.UI.V2ViewModelTabGroup))
        Next
    End Sub
End Class

Public Class ViewModelSharedSettings
    Inherits UIObject

    Public ReadOnly Property ProjectTabVisibility As Windows.Visibility
        Get
            Return If(ModuleDashboarding._activeproject.IsShared, Windows.Visibility.Visible, Windows.Visibility.Collapsed)
        End Get
    End Property

    Public Property GlobalFolder As String
        Get
            Return If(String.IsNullOrEmpty(My.Settings.GlobalSharedFolder), If(String.IsNullOrEmpty(My.Settings.DefaultGlobalSharedFolder), "(Selectionner un dossier)", My.Settings.DefaultGlobalSharedFolder), My.Settings.GlobalSharedFolder)
        End Get
        Set(ByVal value As String)
            My.Settings.GlobalSharedFolder = value
            My.Settings.Save()
            OnPropertyChanged("GlobalFolder")
        End Set
    End Property

    Private _ProjectFolder As String
    Public Property ProjectFolder As String
        Get
            Return _ProjectFolder
        End Get
        Set(ByVal value As String)
            _ProjectFolder = value
            OnPropertyChanged("ProjectFolder")
        End Set
    End Property


End Class